define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";


	var base = require("../../custom/base/component-base.js");

	var async = require("../../custom/base/component-async.js");
	
	var validate = require("../../custom/base/component-validate.js");
	
		
	base.init(base);
	
	
	exports.init=function(m) {
		
		
		base.setFromPage(base.getParameter("fromPage"));
		
		window.$ldh_login = m;
		
	};
	
	

	
	//登录
	exports.login=function(){

		
		var mobile=$("#login_mobile").val();
				
		var password=$("#login_password").val();
		
		if(!validate.isMobile(mobile)){
			
			showTips("请填写正确的手机号码");
		
			return;
		}
		
		if(validate.isNull(password)){
			
			showTips("请输入登录密码");
			
			return;
		}

		/*if("123456" == password || "000000"== password || "111111"== password){
			showTips("密码过于简单，请登录后马上修改密码！");
		}*/
		
		exports.autoLogin(mobile,password,base.getFromPage());
		
	};
	
	//自动登录
	exports.autoLogin=function(mobile,password,fromPage){
		
		
		var params={
				"userName":mobile,
				"password":MD5(password),
				"sessionId":"",
				"sign":MD5(mobile+""+MD5(password)+"")
			};
			
			base.showLoading();
			
			eval(Wind.compile("async", function() {

				var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopapp/Login/login.do", params));

				if(data.code =="1"){
					//登录成功
					//alert(data.code+";"+data.userId+";"+data.userName);
					showTips("登录成功");
					
					base.setCookie("userId",data["userId"]);
					base.setCookie("userName",data["userName"]);
					base.setCookie("mobile",data["mobile"]);
					base.setCookie("loginSign",data["loginSign"]);
					
					if(fromPage=="homepage"){
						window.location.href=ctx+"/h5/mine.shtml";
					}
					else if(fromPage=="ldhMine"){
						
						window.location.href=ctx+"/h5/mine.shtml";
						
					}else if(fromPage=="ldhCart"){
						
						window.location.href=ctx+"/h5/cart.shtml";
						
					}else if(fromPage=="ldhStore"){
						//exports.showDiv("#ldhStore","","?shopId="+exports.getParameter("shopId"));
						//window.location.href=ctx+"/h5/cart.shtml";
						window.location.href=ctx+"/h5/shopIndex/"+base.getParameter("shopId")+".shtml";

					}else if(fromPage=="ldhGoods"){
						//exports.showDiv("#ldhGoods","","?merchandiseId="+exports.getParameter("merchandiseId"));
						window.location.href=ctx+"/h5/merDetail/"+base.getParameter("merchandiseId")+".shtml";
					}else{
						//window.location.href="#ldhHome";
						window.location.href=ctx+"/h5/index.shtml";

					}
					
				}else{
					
					showTips(data.message);
					
				}
				base.cancelLoading();
				
			}))().start();
		
	}
});